package itheima01;

import java.util.Random;
import java.util.Scanner;

/**
 * @author Xiao
 * @date 2021/7/18
 */
public class LambdaDemo06 {
    /**
     * 定义接口ISpeak，接口中定义抽象方法 void sayHello(String name);
     */
    public static void main(String[] args) {
        method(name -> System.out.println("method:\t" + name + "你好！"));
        System.out.println("------------");
        method2(msg -> System.out.println("method2:\tHello " + msg));
        System.out.println("------------");
        method3(() -> {
            Random r = new Random();
            return r.nextInt(10);
        });
        System.out.println("-----------");
        method4(() -> {
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入一个字符串：");
            return sc.nextLine();
        });
        System.out.println("----------");
        method5(arr -> {
            int max = arr[0];
            for (int i : arr) {
                if (max < arr[i]) {
                    max = arr[i];
                }
            }
            return max;
        });
    }

    public static void method(ISpeak is) {
        is.sayHello("老王");
    }

    public static void method2(MessageHanlder m) {
        m.print("itheima");
    }

    public static void method3(RandomHandler rn) {
        int num = rn.getNumber();
        System.out.println("method3:\tnum:" + num);
    }

    public static void method4(IGetString igs) {
        String s = igs.get();
        System.out.println("method4:\t" + s);
    }

    public static void method5(IGetMax igm) {
        int[] arr = {11, 33, 55, 22, 44};
        int max = igm.getMax(arr);
        System.out.println("method5:\tmax:" + max);
    }
}

interface ISpeak {
    void sayHello(String name);
}

interface MessageHanlder {
    void print(String msg);
}

interface RandomHandler {
    int getNumber();
}

interface IGetString {
    String get();//键盘录入一个字符串,并返回
}

interface IGetMax {
    int getMax(int[] arr);  //获取数组元素的最大值
}